home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDSetDiscTitle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  4.4 KB  |  170 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDSetDiscTitle - An XFCN to set the title of the disc.
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/11/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C CDSetDiscTitle.c
  11.     link -sn Main=CDSetDiscTitle -sn STDIO=CDSetDiscTitle ∂
  12.          -sn INTENV=CDSetDiscTitle -rt XFCN=42 ∂
  13.          -m CDSetDiscTitle CDSetDiscTitle.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25. #include <ToolUtils.h>
  26.  
  27. /* prototype definitions for functions */
  28.  
  29. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  30.  
  31.  
  32. /************************************************************************
  33.  *
  34.  *  Function:        CDSetDiscTitle
  35.  *
  36.  *  Purpose:        set the title of this disc.
  37.  *
  38.  *  Returns:        0 if no error
  39.  *                    whatever driver/io errors we might have encountered
  40.  *                    otherwise.
  41.  *
  42.  *  Side Effects:
  43.  *
  44.  *  Description:    We need 1 parameter:  the new name for the disc.
  45.  *                    Get the ioRefNum that we got from previously calling
  46.  *                    CDOpen() by accessing the famous global.
  47.  *                    call the driver with a READTOC call to find out
  48.  *                    the lead-out time.  This is a unique number for each
  49.  *                    disc.  Look in the System Folder for the file
  50.  *                    "CD Remote Programs".  Open that file, look at the
  51.  *                    IndX resource to find out if we've got a matching
  52.  *                    index.  If we do, look up the STR# resource 
  53.  *                    referenced and modify that STR#'s first string to
  54.  *                    be the new string.  If we don't, create a new disc
  55.  *                    entry and then modify the new STR#'s first string
  56.  *                    to be the input string.
  57.  *
  58.  *                    Simple, really.
  59.  *
  60.  ************************************************************************/
  61. pascal void
  62. CDSetDiscTitle(paramPtr)
  63. XCmdBlockPtr    paramPtr;
  64. {
  65.     OSErr    result;
  66.     short    ioRefNum;
  67.     short    vRefNum;
  68.     short    resFile;
  69.     Handle    refHandle;
  70.     Handle    strHandle;
  71.     short    strListID;
  72.     unsigned long    discID;
  73.     short    numberOfTracks;
  74.     Str255    title;
  75.     Str255    newTitle;
  76.     Str255    fileName;
  77.     Str31    returnString;
  78.     
  79.     strcpy(title, "\p");
  80.  
  81.     /* Must be 1 parameter */
  82.     if ((paramPtr->paramCount) != 1)
  83.     {
  84.         /* Report error in parameters by returning -1 */
  85.         NumToStr(paramPtr, (long) -1, &returnString);
  86.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  87.         return;
  88.     }
  89.     /* check that size of input parameter is less than 255 chars */
  90.     if (strlen(*(paramPtr->params[0])) > 255)
  91.     {
  92.         /* Report error in parameters by returning -1 */
  93.         NumToStr(paramPtr, (long) -1, &returnString);
  94.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  95.         return;
  96.     }
  97.     
  98.     /* Get the global ioRefNum, vRefNum pair and split them out. */
  99.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  100.     ioRefNum = atoi(*(refHandle));
  101.     DisposHandle(refHandle);
  102.     vRefNum = ioRefNum >> 16;
  103.     ioRefNum &= 0xFFFF;
  104.  
  105.     result = noErr;
  106.     
  107.     /* Only parameter is a disc title string  */
  108.     HandleToPString(paramPtr->params[0], (Ptr)newTitle);
  109.  
  110.     GetIndString(fileName, STR_ID, DRIVENAME);
  111.     if (fileName == (Str255)0)
  112.         result = ResError();
  113.  
  114.     if (result == noErr)
  115.     {
  116.         resFile = OpenSystemResFile(fileName);
  117.         if (resFile == -1)
  118.             result = ResError();
  119.     }
  120.     
  121.     if (result == noErr)
  122.         result = IDDisc(ioRefNum, &discID);
  123.     
  124.     if (result == noErr)
  125.         result = GetNumberTracks(ioRefNum, &numberOfTracks);
  126.         
  127.     if (result == noErr)
  128.         if (FindIndex(discID, &strListID) == false)
  129.             result = AddDisc(discID, numberOfTracks);
  130.     
  131.     if (result == noErr)
  132.         if (FindIndex(discID, &strListID) == false)
  133.             result = fnfErr;
  134.         /* something's badly wrong at this point */
  135.         /* we've failed to create a valid program entry */
  136.         /* and we're hosed */
  137.     
  138.     if (result == noErr)
  139.     {
  140.         GetIndString(title, strListID, 1);
  141.         strHandle = Get1Resource('STR#', strListID);
  142.         if (strHandle == nil)
  143.             result = ResError();
  144.     }
  145.     
  146.     if (result == noErr)
  147.         Munger(strHandle, 2L, title, title[0]+1, newTitle, newTitle[0]+1);
  148.     
  149.     if (result == noErr)
  150.     {
  151.         ChangedResource(strHandle);
  152.         result = ResError();
  153.     }
  154.     if (result == noErr)
  155.     {
  156.         WriteResource(strHandle);
  157.         result = ResError();
  158.     }
  159.     
  160.     CloseResFile(resFile);
  161.  
  162.     /* Convert result to string & return it */
  163.     NumToStr(paramPtr, (long) result, &returnString);
  164.     paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  165. }
  166.  
  167.  
  168. /* C routines for HyperCard callbacks */
  169. #include <XCmdGlue.inc.c>
  170.